/*
 * MainFrame.java
 *
 * Created on Jan 9, 2011, 8:26:12 PM
 */
package ru.ifmo.itmokis.gui;

import org.jfree.chart.ChartPanel;
import ru.ifmo.itmokis.util.ChartFactory;
import ru.ifmo.itmokis.util.Config;

/**
 *
 * @author ivan
 */
public class MainFrame extends javax.swing.JFrame {

    private Controller controller;
    private Config config;

    /** Creates new form MainFrame */
    public MainFrame(Controller controller, Config config) {
        this.config = config;
        this.controller = controller;
        initComponents();
        playButton.setEnabled(true);
        pauseButton.setEnabled(false);
        controller.setTimeOutput(currentTimeLabel);
        controller.setProductionQueueOutput(productionQueueTextArea);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        playButton = new javax.swing.JButton();
        pauseButton = new javax.swing.JButton();
        currentTimeLabel = new javax.swing.JLabel();
        productionQueueScrollPane = new javax.swing.JScrollPane();
        productionQueueTextArea = new javax.swing.JTextArea();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        settingsMenuItem = new javax.swing.JMenuItem();
        timeHelperMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        chartsMenu = new javax.swing.JMenu();
        productivityMenuItem = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Itmo KIS");
        setResizable(false);

        playButton.setText("Play");
        playButton.setMaximumSize(new java.awt.Dimension(54, 30));
        playButton.setMinimumSize(new java.awt.Dimension(54, 30));
        playButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playButtonActionPerformed(evt);
            }
        });

        pauseButton.setText("Pause");
        pauseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pauseButtonActionPerformed(evt);
            }
        });

        currentTimeLabel.setFont(new java.awt.Font("Ubuntu", 0, 36));
        currentTimeLabel.setText("00w 0h 0d");

        productionQueueTextArea.setBackground(new java.awt.Color(255, 255, 201));
        productionQueueTextArea.setColumns(20);
        productionQueueTextArea.setFont(new java.awt.Font("Nimbus Mono L", 0, 18));
        productionQueueTextArea.setRows(5);
        productionQueueTextArea.setText("Production queue");
        productionQueueTextArea.setMargin(new java.awt.Insets(4, 4, 4, 4));
        productionQueueScrollPane.setViewportView(productionQueueTextArea);

        fileMenu.setText("File");

        settingsMenuItem.setText("Settings");
        settingsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                settingsMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(settingsMenuItem);

        timeHelperMenuItem.setText("Time converter");
        timeHelperMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                timeHelperMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(timeHelperMenuItem);

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        chartsMenu.setText("Charts");

        productivityMenuItem.setText("Productivity");
        productivityMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                productivityMenuItemActionPerformed(evt);
            }
        });
        chartsMenu.add(productivityMenuItem);

        jMenuItem1.setText("Sample");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        chartsMenu.add(jMenuItem1);

        menuBar.add(chartsMenu);

        helpMenu.setText("Help");

        aboutMenuItem.setText("About...");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(productionQueueScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(pauseButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(playButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 245, Short.MAX_VALUE)
                        .addComponent(currentTimeLabel)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(playButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pauseButton))
                    .addComponent(currentTimeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(productionQueueScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playButtonActionPerformed
        playButton.setEnabled(false);
        pauseButton.setEnabled(true);
        controller.play();
    }//GEN-LAST:event_playButtonActionPerformed

    private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseButtonActionPerformed
        playButton.setEnabled(true);
        pauseButton.setEnabled(false);
        controller.pause();
    }//GEN-LAST:event_pauseButtonActionPerformed

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        controller.pause();
        this.dispose();
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        new AboutDialog(this, true).setVisible(true);
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void settingsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsMenuItemActionPerformed
        new SettingsDialog(this, false, config).setVisible(true);
    }//GEN-LAST:event_settingsMenuItemActionPerformed

    private void timeHelperMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeHelperMenuItemActionPerformed
        new TimeHelperDialog(this, false).setVisible(true);
    }//GEN-LAST:event_timeHelperMenuItemActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        ChartFactory cf = new ChartFactory();
        new ChartDialog(this, "Sample", cf.createSampleChart()).setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void productivityMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_productivityMenuItemActionPerformed
        ChartPanel pan = controller.getProdChart();
        new ChartDialog(this, "Productivity", pan).setVisible(true);
    }//GEN-LAST:event_productivityMenuItemActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenu chartsMenu;
    private javax.swing.JLabel currentTimeLabel;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JButton pauseButton;
    private javax.swing.JButton playButton;
    private javax.swing.JScrollPane productionQueueScrollPane;
    private javax.swing.JTextArea productionQueueTextArea;
    private javax.swing.JMenuItem productivityMenuItem;
    private javax.swing.JMenuItem settingsMenuItem;
    private javax.swing.JMenuItem timeHelperMenuItem;
    // End of variables declaration//GEN-END:variables
}
